package ink.yql.dao;

import ink.yql.model.Attention;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author YQL
 */
@Mapper
public interface AttentionDao {
    /**
     * @param uid 用户id
     * @return 关注的用户
     */
    @Select("select * from attention where uid = #{uid}")
    List<Attention> getAttentionByUid(@Param("uid") Integer uid);

    /***
     *
     * @param otherid 被关注的id
     * @return 关注你的用户
     */
    @Select("select * from attention where otherid = #{otherid}")
    List<Attention> getAttentionByOtherid(@Param("otherid") Integer otherid);

    /***
     *
     * @param attention 校验的信息
     * @return 是否存在
     */
    @Select("select * from attention where otherid = #{otherid} and uid = #{uid} ")
    Attention whetherToFollow(Attention attention);

    /**
     * @param attention 添加关注
     * @return 影响行数
     */
    @Insert("insert into attention (uid,otherid) values(#{uid} ,#{otherid} )")
    Integer addOne(Attention attention);

    /***
     * @param attention 取消关注
     * @return  影响行数
     */
    @Delete("delete from  attention where uid = #{uid} and otherid = #{otherid}")
    Integer delete(Attention attention);

}
